import Vue from 'vue'
import VueRouter from 'vue-router'

Vue.use(VueRouter)

const routes = [
  {
    path: '/Login',
    name: 'Login',
    component: () => import('../views/Login.vue')
  },
  {
	path: '/',
	name: 'index',
	component: () => import('../views/index.vue'),
	children : [
		{
			path:'/首页',
			name:'首页',
			component:() => import('../views/首页')
		},
		{
			path:'/echart',
			name:'echart',
			component:() => import('../views/echart')
		},
		{
			path:'/ueditor',
			name:'ueditor',
			component:() => import('../views/ueditor')
		},
		{
			path:'/管理员列表',
			name:'管理员列表',
			component:() => import('../views/管理员列表')
		},
		{
			path:'/角色管理',
			name:'角色管理',
			component:() => import('../views/角色管理')
		},
		{
			path:'/菜单管理',
			name:'菜单管理',
			component:() => import('../views/菜单管理')
		},
		{
			path:'/SQL监控',
			name:'SQL监控',
			component:() => import('../views/SQL监控')
		},
		{
			path:'/定时任务',
			name:'定时任务',
			component:() => import('../views/定时任务')
		},
		{
			path:'/参数管理',
			name:'参数管理',
			component:() => import('../views/参数管理')
		},
		{
			path:'/文件上传',
			name:'文件上传',
			component:() => import('../views/文件上传')
		},
		{
			path:'/系统日志',
			name:'系统日志',
			component:() => import('../views/系统日志')
		},
	]
  }
]

const router = new VueRouter({
  mode: 'history',
  base: process.env.BASE_URL,
  routes
})

var userLoginStatus = false;
router.beforeEach((to,from,next) => {
	var userLoginStatus = localStorage.getItem("token");
	if(to.name === "Login"){
		next()
	} else {
		if(userLoginStatus){
			next()
		} else {
			next('/Login')
		}
	}
})

export default router
